<%@page import="bll.CommonBll"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@page import="util.*"%>
<%@page import="dal.*"%>
<%@ page import="model.*,java.util.*"%>
<%
	int idProject = MiscUtil.getIntUrlParam(request, "idProject");

	String projectName = "All Projects";
	String projectUrl = "projectList.jsp";	
	if(idProject != Integer.MIN_VALUE)
	{
		projectName = CacheUtil.getProjectName(idProject);
		projectUrl = "project.jsp?id=" + idProject;
	}

	GenericDal<AgendaModel, AgendaModelExt> dal = new GenericDal<AgendaModel, AgendaModelExt>(
			new AgendaModel());
	AgendaModelExt queryCount = new AgendaModelExt();
	
	queryCount.setIdProject(idProject);
	
	int count = dal.count(queryCount);
	
	int pageIndex = MiscUtil.getIntUrlParam(request, "pageIndex", 1);
	int pageSize =  MiscUtil.getIntUrlParam(request, "pageSize", 10);

	int noOfPage = count / pageSize;
	if (count % pageSize > 0) {
		noOfPage++;
	}

	AgendaModelExt query = new AgendaModelExt();
	query.setLimit(pageSize);
	query.setOffset((pageIndex - 1) * pageSize);
	
	query.setIdProject(idProject);
	query.setCountItem(true);
	
	List<AgendaModel> list = CommonBll.loadAgendaList(query);

	boolean embedded = MiscUtil.getBoolUrlParam(request, "embedded", false);
%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Agenda List</title>
<%if(!embedded){ %>
		<link rel="stylesheet" href="css/jquery-ui-1.8.14.custom.css" type="text/css" />
		<link rel="stylesheet" href="css/themes/ui-lightness/jquery.ui.all.css" />
		<link rel="stylesheet" href="css/jquery-dialog.css" />
		
		<script language="javascript" type="text/javascript" src="js/jquery.min.js"></script>
		<script type="text/javascript" src="js/jquery-ui-1.8.14.custom.min.js"></script>
		<script language="javascript" type="text/javascript" src="js/common.js"></script>
	<%} %> 
	<link rel="stylesheet" href="css/listForm.css" />
	<link rel="stylesheet" href="css/common.css" />
	<script language="javascript" type="text/javascript">
		$(document).ready(pageLoaded);
		function pageLoaded()
		{	
			initDeleteConfirmation();
		} 
	</script>
</head>
<body>
	<% if (!embedded) { %>
	<div class="divContainer">	
		<%@ include file="menu.jsp"%>
		<br />
		<b>Project: <a id="link_project" name="link_project" href="<%=projectUrl %>"><%=projectName %></a></b>
		<br />
		<br />
		<a style="font-weight: bold;" href="agendaNew.jsp?idProject=<%=idProject%>">Add New Agenda</a>
		<br />
		<a style="font-weight: bold;" href="projectList.jsp">Go Up to Project List</a>
		<br />
		<br />
	<%}%>
	
		<div class="divListHeaderBar">NUMBER OF AGENDAS: <%=count%></div>	
		<table class="tblList">
			<tr class="tblListHeader">
				<!-- 			<th class="tdListHeader"></th> -->
				<th class="thListHeader">Agenda</th>
				<th class="thListHeader"></th>
				<th class="thListHeader Id">Id</th>
				<th class="thListHeader">Project</th>
				<!-- <th class="thListHeader">Event</th> -->
				<th class="thListHeader">Name</th>
				<th class="thListHeader">Event</th>
				<th class="thListHeader">Description</th>
				<th class="thListHeader">Author</th>
				<th class="thListHeader">Approver</th>
				<th class="thListHeader">Start Time</th>
				<th class="thListHeader">Venue</th>
				<th class="thListHeader">Status</th>
				<!-- <th class="thListHeader">Notification</th> -->
				<!-- <th class="thListHeader">Created</th> -->
				<!-- <th class="thListHeader">Creator</th> -->
				<!-- <th class="thListHeader">Updated</th> -->
				<!-- <th class="thListHeader">Updator</th> -->
				<!-- <th class="thListHeader">Deleted</th> -->
				<!-- <th class="thListHeader">Deletion Time</th> -->
	
				
			</tr>
	
			<%
				int size = list.size();
				for (int i = 0; i < size; i++) {
					AgendaModel obj = list.get(i);
			%>
	
			<tr class="trListItem">
				<td class="tdListInt">
				<span><%=i + 1%></span>
				<br/>
				<span class="spanEdit"><a href="agenda?mode=edit&id=<%=obj.getId()%>">Edit</a></span>
				<br/>
				<span class="spanEdit"><a class="hrefDelete" href="agenda?mode=delete&id=<%=obj.getId()%>&idProject=<%=obj.getIdProject() %>"  onclick="confirmToDelete();">Delete</a></span>
				</td>
				<td class="tdListHref">
					<a
						href="agendaItemNew.jsp?idAgenda=<%=obj.getId()%>">Add item</a>
					<br/>
					[<%=obj.getItemCount()%>]
				</td>
				<td class="tdListInt"><%=obj.getId()%></td>
				<td class="tdListInt"><%=CacheUtil.getProjectName(obj.getIdProject())%></td>
				<td class="tdListText projectName">
					<a href="agenda.jsp?id=<%=obj.getId() %>"><%=obj.getNameToString()%></a>				
				</td>
				<td class="tdListInt"><%=CacheUtil.getEventName(obj.getIdEvent())%></td>
				<td class="tdListTextarea"><%=obj.getDescriptionToString()%></td>
				<td class="tdListInt"><%=CacheUtil.getEmployeeName(obj.getIdAuthor())%></td>
				<td class="tdListInt"><%=CacheUtil.getEmployeeName(obj.getIdApprover())%></td>
				<td class="tdListDateTime"><%=StringUtil.toDateTimeString(obj.getStartTime())%></td>
				<td class="tdListInt"><%=CacheUtil.getVenueName(obj.getIdVenue())%></td>
				<td class="tdListInt"><%=StringUtil.getAgendaStatus(obj.getStatus())%></td>
				<%-- <td class="tdListInt"><%=obj.getNotificationToString()%></td> --%>
				<%-- <td class="tdListDateTime"><%=StringUtil.toDateTimeString(obj.getCreated())%></td> --%>
				<%-- <td class="tdListInt"><%=obj.getCreatorToString()%></td> --%>
				<%-- <td class="tdListDateTime"><%=StringUtil.toDateTimeString(obj.getUpdated())%></td> --%>
				<%-- <td class="tdListInt"><%=obj.getUpdatorToString()%></td> --%>
				<%-- <td class="tdListBool"><%=HtmlUtil.genHtml(obj.getDeleted())%></td> --%>
				<%-- <td class="tdListDateTime"><%=StringUtil.toDateTimeString(obj.getDeletionTime())%></td> --%>

			</tr>
			<%
				}
			%>
		</table>
		<br />
		<%
		if(noOfPage>1)
		{
		%>
		<table class="tblPaging">
			<tr class="trPaging">
				<td class="tdPaging">
					<%
						for (int i = 1; i <= noOfPage; i++) {
							if (i == pageIndex) {
					%> <span class="lblPaging"><%=i%></span> <%
	 	} else {
	 %> <a class="hrefPaging"
					href="agendaList.jsp?pageIndex=<%=i%>&pageSize=<%=pageSize%>"><%=i%></a>
					<%
						}
						}
					%>
				</td>
			</tr>
		</table>
		<%} %>
	<%if(!embedded){ %> </div> <%} %>
</body>
</html>